package com.example.projectcode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.projectcode.mapper.ChapterMapper;
import com.example.projectcode.model.Chapter;
import com.example.projectcode.service.ChapterService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> implements ChapterService {
    @Override
    public List<Chapter> selectAllChapterBySubid(Integer subid) {
        QueryWrapper<Chapter> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("Subid",subid);

        return baseMapper.selectList(queryWrapper);
    }



    @Override
    public List<Chapter> selectChapterByKeyWord(String keyWord) {
        QueryWrapper<Chapter> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("Chapname",keyWord);

        List<Chapter> chapterList = baseMapper.selectList(queryWrapper);
        return chapterList;
    }

    @Override
    public List<Chapter> selectAllChapter() {
        return baseMapper.selectList(new QueryWrapper<Chapter>());
    }

    @Override
    public int insertChapter(Chapter chapter) {
        return baseMapper.insert(chapter);
    }

    @Override
    public int deleteChapterById(Integer chapterId) {
        return baseMapper.delete(new QueryWrapper<Chapter>().eq("Chapid",chapterId));
    }

    @Override
    public Chapter selectChapterByName(String chapterName) {
        return baseMapper.selectOne(new QueryWrapper<Chapter>().eq("Chapname",chapterName));
    }


}
